package cn.edu.xmist.beandifinition.util;

import cn.edu.xmist.beandifinition.Y;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @author zhongjinbin 2021/5/5
 * @since 1.0.0
 */
@Component
public class MyBeanFactoryPostProcess implements BeanFactoryPostProcessor {

    /**
     * 执行时机：扫描完类---类---BeanDifinition之后
     * 实例化Bean之前
     *
     * @param configurableListableBeanFactory
     * @throws BeansException
     */
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        GenericBeanDefinition beanDefinition = (GenericBeanDefinition) configurableListableBeanFactory.getBeanDefinition("x");
        beanDefinition.setBeanClass(Y.class);
        beanDefinition.setScope("prototype");
    }
}
